home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-02-16 | 1.4 KB | 91 lines | [TEXT/GEOL] |
- Item 5509806 13-Feb-90 13:24PST
-
- From: D4695 Skywalker Sys, Scott Collins,PRT
-
- To: CPLUS.DEV$ C++ Interest List--Developers
-
- Sub: C++ access control bug
-
- Hello,
- the following complete program demonstrates what Neal Goldstien and I think
- is a bug in implementation of the C++ translator.
-
- // == cut here ==========
-
-
- #include <iostream.h>
-
- class A
- {
- public:
- A( char *name );
-
- char *Name();
- void legal();
- void illegal( A& a );
-
- private:
- void g( A *caller );
-
- private:
- char *fName;
- };
-
- // ----------
-
- inline A::A( char *name )
- { fName = name; }
-
- // ----------
-
- inline char *A::Name()
- { return fName; }
-
- // ----------
-
- void A::illegal( A& a )
- {
- a.g( this );
- }
-
- // ----------
-
- void A::legal()
- {
- this->g( this );
- }
-
- // ----------
-
- void A::g( A *caller )
- {
- cout << this->Name() << ".g() -- called by " << caller->Name() << endl;
- }
-
- // ----------
-
- main()
- {
- A a1( "a1" );
- A a2( "a2" );
-
- a1.legal();
- a1.illegal( a2 );
-
- }
-
- // == cut here ==========
-
- The output of this program (which compiles correctly) is --
-
- a1.g() -- called by a1
- a2.g() -- called by a1
-
- Both Neal and I previously assumed that private meant private to an object not
- private to a class.
-
- Is this a bug and if so to whom should it be reported?
-
- -- Scott Collins
-
-